package ar.com.ford.it.fullEconomics.persistence.dao.query;

import java.sql.Timestamp;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp02Commodity;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class CommodityPartsFindByDateQuery implements CustomExpressionFactory {

    public Expression createExpression(ExpressionBuilder builder,
                                       Object[] parameters) {
        Expression exp = null;
        Teesp02Commodity commodity = (Teesp02Commodity) parameters[0];
        Timestamp date = (Timestamp) parameters[1];
        
        exp = builder.get("eesp03PlantCodeC").equal(commodity.getEesp02PlantCodeC());
        exp = exp.and(builder.get("teesp02Commodity").equal(commodity));
        exp = exp.and(builder.get("eesp03CommodPartInDateY").lessThanEqual(date));
        exp = exp.and(builder.get("eesp03CommodPartOutDateY").greaterThanEqual(date));
        
        return exp;
    }

}
